<?php

	include($_SERVER['DOCUMENT_ROOT']."/eventos/sistema/common/login/seguranca.php"); // Inclui o arquivo com o sistema de segurança
	include($_SERVER['DOCUMENT_ROOT']."/eventos/sistema/common/paginacao.php");

	protegePagina(); // Chama a função que protege a página
	if(!isset($_SESSION)) {
 	 SESSION_START();
	}


	$idEvento	=	$_GET["idEvento"];
	$operacao	= 	$_GET["operacao"];
	$idEvento	=	$_GET["idEvento"];
	$idUsuario	=	$_GET['idUsuario'];
	$acao		=	$_GET['acao'];
	$bolMarcado = 	$_GET['bolMarcado'];
	$idSituacao = 	0;


	if($operacao == 'alterar'){
		alterarSituacao();
	}

	function alterarSituacao(){

	global $idEvento, $idEmpresa, $idEvento, $idUsuario, $acao, $bolMarcado, $idSituacao;

	if($acao == "ps"){
		if($bolMarcado){
			$idSituacao = 1;
		}

	}

	else if($acao == "s"){
		if($bolMarcado){
			$idSituacao = 2;
			$acaoParticipante = "insert";
		}

	}
	else{
		if($bolMarcado){
			$idSituacao = 3;
		}

	}


	/*echo 	"idEvento" . " - " . $idEvento . " / " . "idEmpresa" . " - " . $idEmpresa . " / " .
			"idUsuario" . " - " . $idUsuario . " / " . "acao" . " - " . $acao . " / " .
			"bolMarcado" . " - " . $bolMarcado . " / " . "idSituacao" . " - " . $idSituacao . " / " ;

	*/



		if($acaoParticipante == "insert"){
			$queryParticipante = "INSERT INTO `tblparticipanteevento`
											 (`idEvento`, `idUsuario` )
											VALUES
											 ('$idEvento', '$idUsuario') ";
		}
		else{
			$queryParticipante = "DELETE FROM tblparticipanteevento
									WHERE 	`idUsuario`  = '$idUsuario'
									AND	`idEvento`   = '$idEvento' ";
		}



		mysql_query($queryParticipante) or die(mysql_error());

		$queryUpdateCandidato = "UPDATE `tblcandidatoevento`
								 SET	`idSituacao` = '$idSituacao'
								 WHERE 	`idUsuario`  = '$idUsuario'
								 AND	`idEvento`   = '$idEvento' ";



		mysql_query($queryUpdateCandidato) 			or die(mysql_error());

	}

?>







<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>


<?php
	$listaCandidatosS = "SELECT DP.strNome
						FROM tblcandidatoevento CE ,
							 tbldadospessoais DP
						where idEvento = $idEvento
						and CE.idUsuario = DP.idUsuario
						and CE.idSituacao = 2 " ;
	$listaCandidatosPS = "SELECT DP.strNome
						FROM tblcandidatoevento CE ,
							 tbldadospessoais DP
						where idEvento = $idEvento
						and CE.idUsuario = DP.idUsuario
						and CE.idSituacao = 1 " ;
	$listaCandidatosD = "SELECT DP.strNome
						FROM tblcandidatoevento CE ,
							 tbldadospessoais DP
						where idEvento = $idEvento
						and CE.idUsuario = DP.idUsuario
						and CE.idSituacao = 3 " ;

	$listaCandidatosS  = mysql_query($listaCandidatosS) or die(mysql_error());
	$listaCandidatosPS = mysql_query($listaCandidatosPS) or die(mysql_error());
	$listaCandidatosD  = mysql_query($listaCandidatosD) or die(mysql_error());

	$contS	= 0;
	$contPS	= 0;
	$contD	= 0;


?>






<div style="border:solid 1px; border-color:#CCCCCC; text-align:center; background-image:url(Img/lixao/Plano_de_fundo_cinza2.png); background-repeat:repeat-x; border-bottom:none; border-top-left-radius:11px; border-top-right-radius:11px;width:300px;height:40px;">
	<font face="Arial, Helvetica, sans-serif" size="+1" color="#3366FF">Candidatos(as) selecionados(as)</font>
</div>
<div style="border:solid 1px; border-color:#CCCCCC; border-top:none;width:300px;text-align:center">
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center">

<?php
	if(mysql_num_rows($listaCandidatosS) > 0){
		while ($arrayListaCandidatoS = mysql_fetch_array($listaCandidatosS)){
			$contS = $contS + 1;
		?>
			<tr <?php if (fmod( $contS, 2) == 1){ ?> bgcolor="#DBDBDB" <?php }else ?> bgcolor="#FFFFFF">
				<td>
				<?php echo $arrayListaCandidatoS[strNome]?>
				</td>
			</tr>
<?php
		}
	}
	else{
?>
	<tr>
    	<td>Nenhum candidato(a) selecionado(a)!</td>
    </tr>

<?php   }

?>
</table>

</div>

<br />
<div style="border:solid 1px; border-color:#CCCCCC; text-align:center; background-image:url(Img/lixao/Plano_de_fundo_cinza2.png); background-repeat:repeat-x; border-bottom:none; border-top-left-radius:11px; border-top-right-radius:11px;width:300px;height:40px;">
	<font face="Arial, Helvetica, sans-serif" size="+1" color="#3366FF">Candidatos(as) pré selecionados(as)</font>
</div>
<div style="border:solid 1px; border-color:#CCCCCC; border-top:none;width:300px;text-align:center">
<table width="100%" cellpadding="0" cellspacing="0" border="0">

<?php
	if(mysql_num_rows($listaCandidatosPS) > 0){
		while ($arrayListaCandidatoPS = mysql_fetch_array($listaCandidatosPS)){
			$contPS = $contPS + 1;
		?>
			<tr <?php if (fmod( $contPS, 2) == 1){ ?> bgcolor="#DBDBDB" <?php }else ?> bgcolor="#FFFFFF">
				<td>
				<?php echo $arrayListaCandidatoPS[strNome]?>
				</td>
			</tr>
<?php
		}
	}
	else{
?>
	<tr>
    	<td>Nenhum candidato(a) selecionado(a)!</td>
    </tr>

<?php   }

?>
</table>

</div>
<br />
<div style="border:solid 1px; border-color:#CCCCCC; text-align:center; background-image:url(Img/lixao/Plano_de_fundo_cinza2.png); background-repeat:repeat-x; border-bottom:none; border-top-left-radius:11px; border-top-right-radius:11px;width:300px;height:40px;">
	<font face="Arial, Helvetica, sans-serif" size="+1" color="#3366FF">Candidatos(as) descartados(as)</font>
</div>
<div style="border:solid 1px; border-color:#CCCCCC; border-top:none;width:300px;text-align:center">
<table width="100%" cellpadding="0" cellspacing="0" border="0">

<?php
	if(mysql_num_rows($listaCandidatosD) > 0){
		while ($arrayListaCandidatoD = mysql_fetch_array($listaCandidatosD)){
			$contD = $contD + 1;
		?>
			<tr <?php if (fmod( $contD, 2) == 1){ ?> bgcolor="#DBDBDB" <?php }else ?> bgcolor="#FFFFFF">
				<td>
				<?php echo $arrayListaCandidatoD[strNome]?>
				</td>
			</tr>
<?php
		}
	}
	else{
?>
	<tr>
    	<td>Nenhum candidato(a) selecionado(a)!</td>
    </tr>

<?php   }

?>
</table>

</div>
</body>
</html>